package day02;

import javax.swing.*;
import java.util.ArrayList;

public class Yang01 {
    public static void main(String[] args) {
        //创建牌
        JFrame frame = new JFrame("羊了个羊");
        //创建面板
        JPanel panel = new JPanel();
        frame.add(panel);
        panel.setLayout(null);
        //创建背景
        JLabel backgound = new JLabel(new ImageIcon("res/背景.jpg"));
        backgound.setSize(480,800);
        panel.add(backgound);
        //1.创建牌
       ArrayList<JButton> cards = createCard(3);//25*3
        System.out.println(cards.size());
        //2.洗牌

        //3.摆拍



        frame.setSize(495,800);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

    }
    /**
     * 封装创建牌的方法
     * 1.因为创建的牌 需要装到集合中,所以要有返回值类型  ArrayList<JButton>
     * 2.我们在创建牌时按照轮数创建
     */
    public static ArrayList<JButton> createCard(int rounds){
        //1.定义数组  存储卡牌的名称
        String [] names  = {
                "兔子","刷子","剪刀","南瓜","奶瓶","帽子","干草","手套","月饼","树",
                "树桩","栗子","毛线","水桶","火堆","白菜","耙子","苹果","草","萝卜",
                "蜜蜂","酒坛","铃铛","面具","饭团"
        };
        //2.定义集合存储卡牌
        ArrayList<JButton> cards = new ArrayList<>();
        //3.利用循环遍历将卡牌存储到集合中
        for (int j = 0; j < rounds ; j++) {
            for (int i = 0; i < names.length; i++) {
                String fileName = "res/" + names[i] + ".png";
                JButton card = new JButton(new ImageIcon(fileName));
                card.setSize(59, 66);
                cards.add(card);

            }
        }
        //4.返回集合
        return cards;
    }
}
